iT邦幫忙

2024 iThome 鐵人賽

DAY 9
0
JavaScript

大樂透對獎系列 第 9

陣列

  • 分享至 

  • xImage
  •  

int[][] cords = new int[][] {
{1, 3, 5},
{2, 4, 6}
};

解釋為:

int[][]cords分為:
int[0]---{1, 3, 5}
int[1]---{2, 4, 6}

理解以上程式碼之後,可以知道二維陣列不一定得是方陣,也可以建立不規則陣列。
同理:

int[][] arr = {
{1, 3, 5, 7, 9},
{2, 4, 6}
};

以上程式碼也能成立。

new關鍵字建立Integer陣列:

package cc.openhome;

public class IntegerArray {
public static void main(String[] args) {
Integer[] scores = new Integer[3];
for(Integer score : scores) {
System.out.println(score);
}

    scores[0] = 86;
    scores[1] = 82;
    scores[2] = 91;

    for(Integer score : scores) {
        System.out.println(score);
    }
}

}

結果為:

null
null
null
86
82
91

以下為Integer二維陣列:

Integer[][] cords = new Integer[3][2];

若是區域變數,也可以使用var簡化:

var cords = new Integer[3][2];

以上答案是0個。


上一篇
陣列
下一篇
字串
系列文
大樂透對獎13
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言